package com.hui.account.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.hui.account.activity.AboutActivity;
import com.hui.account.R;
import com.hui.account.activity.RecoverActivity;
import com.hui.account.activity.SettingActivity;
import com.hui.account.activity.UserActivity;
import com.hui.account.utils.ToastUtils;

/**
 * 首页：更多选项
 */
public class MoreDialog extends Dialog implements View.OnClickListener {

    Button aboutBtn, settingBtn, userBtn, appLogBtn, recycleBtn, recordInfoBtn;
    ImageView backView;

    public MoreDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_more);

        // 1、初始化页面
        initView();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.dialog_more_about:
                view.getContext().startActivity(new Intent(view.getContext(), AboutActivity.class));
                cancel();
                break;
            case R.id.dialog_more_setting:
                view.getContext().startActivity(new Intent(view.getContext(), SettingActivity.class));
                cancel();
                break;
            case R.id.dialog_more_user:
                view.getContext().startActivity(new Intent(view.getContext(), UserActivity.class));
                cancel();
                break;
            case R.id.dialog_more_app_log:
                ToastUtils.success(getContext(), "敬请期待", Gravity.TOP, 0, 15);
                break;
            case R.id.dialog_more_recycle:
                view.getContext().startActivity(new Intent(view.getContext(), RecoverActivity.class));
                cancel();
                break;
            case R.id.dialog_more_record_info:
                ToastUtils.success(getContext(), "敬请期待", Gravity.TOP, 0, 15);
                break;
            case R.id.dialog_more_back:
                cancel();
                break;
        }
    }

    /**
     * 初始化页面
     */
    private void initView() {
        aboutBtn = findViewById(R.id.dialog_more_about);
        settingBtn = findViewById(R.id.dialog_more_setting);
        userBtn = findViewById(R.id.dialog_more_user);
        appLogBtn = findViewById(R.id.dialog_more_app_log);
        recycleBtn = findViewById(R.id.dialog_more_recycle);
        recordInfoBtn = findViewById(R.id.dialog_more_record_info);
        backView = findViewById(R.id.dialog_more_back);

        aboutBtn.setOnClickListener(this);
        settingBtn.setOnClickListener(this);
        userBtn.setOnClickListener(this);
        appLogBtn.setOnClickListener(this);
        recycleBtn.setOnClickListener(this);
        recordInfoBtn.setOnClickListener(this);
        backView.setOnClickListener(this);
    }

    /**
     * 设置 dialog尺寸与屏幕尺寸保持一致
     */
    public void setDialogSize() {
        Window window = getWindow();
        Display display = window.getWindowManager().getDefaultDisplay();

        WindowManager.LayoutParams params = window.getAttributes();
        params.width = display.getWidth();
        params.gravity = Gravity.BOTTOM;
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(params);
    }
}
